package com.hrserviceserve.service;

import cn.hutool.crypto.SecureUtil;
import com.hrserviceserve.dao.UserRepository;
import com.hrserviceserve.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {
    @Autowired
    UserRepository userRepository;
    public User login(User user){
        String password=SecureUtil.md5(user.getPassword());
        return userRepository.findByUsernameAndPassword(user.getUsername(),password);
    }
    public User save(User user){
        user.setPassword(SecureUtil.md5(user.getPassword()));
        return userRepository.save(user);
    }
    @Transactional
    public int deleteByName(String username){
        return userRepository.deleteByUsername(username);
    }
    public User info(String username){
        return userRepository.findByUsername(username);
    }

    public int upava(String username,String ava){
        return userRepository.upava(username,ava);
    }
    public int uppwd(String a,String b){
        String pwd=SecureUtil.md5(b);
        return userRepository.uppwd(a,pwd);
    }
}
